package com.example.park_2306.video

import android.os.Bundle
import android.webkit.JavascriptInterface
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.entity.VideoEntityItem
import com.example.base.mvi.BaseActivity
import com.example.park_2306.R
import com.example.park_2306.databinding.ActivityVideoDetailBinding
import com.tencent.smtt.sdk.WebViewClient
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/VideoDetailActivity")
@AndroidEntryPoint
class VideoDetailActivity : BaseActivity<ActivityVideoDetailBinding,VideoIntent,VideoViewModel>() {

    //一种传了一个字段例如id  一种传了整个实体类
    @Autowired
    @JvmField
    var vid = -1

    @Autowired
    lateinit var video:VideoEntityItem
    override fun getLayout(): Int  = R.layout.activity_video_detail

    override fun getVM(): Class<VideoViewModel>  = VideoViewModel::class.java

    override fun initView() {
        ARouter.getInstance().inject(this)
        //使用webview展示视频
        binding.wv.apply {
            loadUrl(video.videopath)
            webViewClient = WebViewClient()
        }

     /*   binding.gsy.setUp(video.videopath,true,"")
        binding.gsy.backButton.isVisible = false
        binding.gsy.startPlayLogic()*/
       //webview 来执行Android 和 js交互
        binding.wvJs.apply {
            loadUrl("file:///android_asset/test.html")
            webViewClient = WebViewClient()
            settings.javaScriptEnabled = true
        }
        //安卓调用js
        binding.btn.setOnClickListener {
            binding.wvJs.loadUrl("javascript:harmonyCallJS()")
        }
        //js调用安卓
        binding.wvJs.addJavascriptInterface(this,"android")

    }

    override fun initData() {

    }
    @JavascriptInterface
    fun harmonyosAgree():String{
        return "aaahjfksaloi"
    }

}